package chelydra.sharelydra.server.ejb;

import java.util.Collection;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/**
 *
 * @author scallion
 */
@Entity
public class SLSUser implements Serializable {

	/**
	 * Properties
	 */
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	private String login;
	private String password;
	private String nickname;
	private String lastName;
	private String firstName;
	private String email;
	private String ip;
	private Integer port;
	private Integer hideInSearch;
	private Integer hideEmail;
	@ManyToMany (fetch = FetchType.EAGER)
	private Collection<SLSUser> friends;

	/**
	 * Getters and Setters
	 */
	// <editor-fold defaultstate="collapsed" desc="Getters/Setters">
	public Long getId() {
		return id;
	}
	protected void setId(Long id) {
		this.id = id;
	}

	public Collection<SLSUser> getFriends() {
		return friends;
	}
	public void setFriends(Collection<SLSUser> friends) {
		this.friends = friends;
	}

	public String getIp() {
		return ip;
	}
	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getLogin() {
		return login;
	}
	public void setLogin(String login) {
		this.login = login;
	}

	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public Integer getPort() {
		return port;
	}

	public void setPort(Integer port) {
		this.port = port;
	}

	public Integer getHideInSearch() {
		return hideInSearch;
	}

	public void setHideInSearch(Integer hideInSearch) {
		this.hideInSearch = hideInSearch;
	}

	public void hideInSearch(boolean hide) {
		if (hide)
			this.setHideInSearch(1);
		else this.setHideInSearch(0);
	}

	public Integer getHideEmail() {
		return hideEmail;
	}

	public void setHideEmail(Integer hideEmail) {
		this.hideEmail = hideEmail;
	}

	public boolean hidesEmail() {
		if (this.hideEmail>0)
			return true;
		else return false;
	}
	// </editor-fold>

	public SLSUser() {}

	public boolean isConnected() {
		return (this.getIp().length()>0);
	}

	@Override
	public int hashCode() {
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals(Object object) {
		// TODO: Warning - this method won't work in the case the id fields are not set
		if (!(object instanceof SLSUser)) {
			return false;
		}
		SLSUser other = (SLSUser) object;
		if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "chelydra.sharelydra.server.ejb.SLSUser[id=" + id + "]";
	}
		
}
